<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
    <title>发布APK</title>
    <%@ include file="/resources/js/easyui/taglibs.jsp" %>
    <%@ include file="/resources/js/easyui/_easyui.jsp" %>
    <%@ include file="/resources/js/easyui/_message.jsp" %>
    <%@ include file="/resources/js/easyui/_viewJS.jsp" %>
</head>

<body>

<div id="tb" style="padding:5px;height:auto;">
    <table>
        <tr>
            <td><label style="margin-left:5px">姓名:</label></td>
            <td>
                <input style="width:150px" id="name" class="easyui-textbox"/>
            </td>
            <td><label style="margin-left:5px">手机号码:</label></td>
            <td>
                <input style="width:150px" id="mobile" class="easyui-textbox"/>
            </td>
            <td><label style="margin-left:5px">银行卡号:</label></td>
            <td>
                <input style="width:150px" id="cardnumber" class="easyui-textbox"/>
            </td>
            <td>
                <a href="javascript:;" style="margin-left: 10px;vertical-align:middle" class="easyui-linkbutton"
                   iconCls="icon-search" id="queryDataBtn">查询</a>
            </td>
        </tr>
    </table>

    <div id="button">
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add" id="addWinBtn">进件初审</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add"
           id="setupBusinessInfoWinBtn">设置用户商户号</a>
    </div>

</div>

<table id="dg"
       title="客户资料进件"
       fitColumns="true"
       singleSelect="true"
       data-options="
       pageSize:10,
       toolbar:'#tb',
       pagination:true,
       collapsible:true,
       url:'${basePath}web/giveinfo/list.json',
       method:'GET'">
    <thead>

    <tr>
        <th data-options="field:'cardid',checkbox:true,width:10"></th>
        <th data-options="field:'userid',width:10,hidden:true"></th>
        <th data-options="field:'username' ,width:50" align="center">用户名</th>
        <th data-options="field:'cardholder' ,width:50" align="center">持卡人</th>
        <th data-options="field:'mobile' ,width:50" align="center">手机号码</th>
        <th data-options="field:'bankname' ,width:80" align="center">银行名称</th>
        <th data-options="field:'bankcardnumber' ,width:150" align="center">银行卡号</th>
        <th data-options="field:'accounttype' ,width:80" align="center" formatter="formatterAccountType">账户类型</th>
        <th data-options="field:'clearingcycle' ,width:50" align="center" formatter="formatterClearingCycle">结算周期</th>
        <th data-options="field:'cardconfirmed' ,width:50" align="center" formatter="formatterState">审核状态</th>
        <th data-options="field:'comment' ,width:150" align="center">审核备注</th>
        <th data-options="field:'createtime' ,width:100" align="center" formatter="formatterTime">进件时间</th>
    </tr>

    </thead>
</table>

<!-- 审核窗体s -->
<div id="addWin" class="easyui-window" minimizable="false"
     collapsible="false" title="进件初审窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:660px;height:650px;">
    <div id="addWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="addSubBtn">确定</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeAddWinBtn">取消</a>
        </div>
    </div>
</div>
<!-- 审核窗体e -->

<!-- 设置用户商户信息窗体s -->
<div id="setupBusinessInfoWinWin" class="easyui-window" minimizable="false"
     collapsible="false" title="设置用户商户信息窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:500px;height:250px;">
    <div id="setupBusinessInfoWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="setupBusinessInfoWinSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeSetupBusinessInfoWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 设置用户商户信息窗体s -->

</body>

<script type="text/javascript">
    function View() {
        var that = this;

        that.events = [
            {sel: '#queryDataBtn', act: 'click', func: 'queryData'},
            {sel: '#addWinBtn', act: 'click', func: 'addWin'},
            {sel: '#addSubBtn', act: 'click', func: 'addSub'},
            {sel: '#closeAddWinBtn', act: 'click', func: 'closeAddWin'},
            {sel: '#setupBusinessInfoWinBtn', act: 'click', func: 'openUserBusinessInfoWin'},
            {sel: '#setupBusinessInfoWinSubBtn', act: 'click', func: 'saveBusinessInfoSub'},
            {sel: '#closeSetupBusinessInfoWinBtn', act: 'click', func: 'closeBusinessInfoWin'}
        ];

        that.$dataGrid = $('#dg');

        that.$addWin = $('#addWin');
        that.$addWinDetailTable = $("#addWinDetailTable");

        that.$setupUserBusinessInfoWin = $('#setupBusinessInfoWinWin');
        that.$setupUserBusinessInfoWinDetailTable = $("#setupBusinessInfoWinDetailTable");

        that.dataGridOption = {
            queryParams : {
                cardholder : function(){return $('#name').val();},
                mobile : function(){return $('#mobile').val();},
                bankcardnumber : function(){return $('#cardnumber').val();}
            }
        };

        $.extend(that.dataGridOption, ViewHelper.template.gridOption);

        that.$dataGrid.datagrid(that.dataGridOption);

        that.queryData = function () {
            that.$dataGrid.datagrid(that.dataGridOption);
        };

        var userid = 0;

        that.addWin = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择一条', "error");
                return;
            }

            userid = row.userid;

            var url = "${basePath}web/giveinfo/" + row.cardid + "/auditview";
            that.$addWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$addWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='add_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$addWin.dialog('open');
        };

        that.addSub = function () {
            $("#add_iframe")[0].contentWindow.add();
        };

        that.closeAddWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.confirm("操作提示", "审核通过,是否为该用户设置商户号?", function (r) {
                    if (r) {
                        that.openUserBusinessInfoWin();
                    }else{
                        userid = 0;
                    }
                });

                /* $.messager.alert('提示', '保存成功!', 'info');*/
            } else if (result == 0) {
                userid = 0;
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$addWin.window('close');
        };

        /* 设置用户商业信息窗体  */
        that.openUserBusinessInfoWin = function () {
            if (typeof(userid) == "undefined" || 0 == userid) {
                var row = that.$dataGrid.datagrid('getSelected');
                if (row == null) {
                    $.fn.window.defaults.top = 50;
                    $.messager.alert('警告', '请选择一条', "error");
                    return;
                }
                userid = row.userid;
            }

            var url = "${basePath}web/giveinfo/" + userid + "/showUserBusinsessInfo";
            that.$setupUserBusinessInfoWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$setupUserBusinessInfoWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='add_businessInfo_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$setupUserBusinessInfoWin.dialog('open');
        };

        that.saveBusinessInfoSub = function () {
            $("#add_businessInfo_iframe")[0].contentWindow.addBusinessInfo();
        };

        that.closeBusinessInfoWin = function (result) {

            userid = 0;

            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$setupUserBusinessInfoWin.window('close');
        };
        /* 设置用户商业信息窗体 */

        EventHandler.call(that, that.events);

        return that;
    }

    var view;

    $(function () {
        inherit(View, EventHandler);
        view = new View();
    });

    function formatterTime(value, row, index) {
        var date = new Date(value);
        var year = date.getFullYear().toString();
        var month = (date.getMonth() + 1);
        var day = date.getDate().toString();
        var hour = date.getHours().toString();
        var minutes = date.getMinutes().toString();
        var seconds = date.getSeconds().toString();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        if (hour < 10) {
            hour = "0" + hour;
        }
        if (minutes < 10) {
            minutes = "0" + minutes;
        }
        if (seconds < 10) {
            seconds = "0" + seconds;
        }
        return year + "年" + month + "月" + day + "日 " + hour + ":" + minutes + ":" + seconds;
    }

    function formatterAccountType(value, row, index) {
        var accounttype = "";
        if (value == 0) {
            accounttype = "个人账户";
        } else {
            accounttype = "对公账户";
        }
        return accounttype;
    }

    function formatterClearingCycle(value, row, index) {
        return "T+" + value;
    }

    function formatterState(value, row, index) {
        var state = "";
        if (value == 0) {
            state = "审核中";
        } else if (value == 1) {
            state = "通过";
        } else if (value == 2) {
            state = "未通过";
        }
        return state;
    }

</script>

</html>